package com.tanglongan.designPattern.dp02_abstractFactory.demo99;

public class GenericClient {

    /**
     * 产品A抽象
     */
    public interface IProductA {
        void doA();
    }

    /**
     * 产品B抽象
     */
    public interface IProductB {
        void doB();
    }

    /**
     * 产品族A：具体产品A
     */
    static class ConcreteProductAWithFamilyA implements IProductA {
        @Override
        public void doA() {
            System.out.println("The ProductA be part of FamilyA");
        }
    }

    /**
     * 产品族A：具体产品B
     */
    static class ConcreteProductBWithFamilyA implements IProductB {
        @Override
        public void doB() {
            System.out.println("The ProductB be part of FamilyA");
        }
    }

    /**
     * 产品族B：具体产品A
     */
    static class ConcreteProductAWithFamilyB implements IProductA {
        @Override
        public void doA() {
            System.out.println("The ProductA be part of FamilyB");
        }
    }

    /**
     * 产品族B：具体产品B
     */
    static class ConcreteProductBWithFamilyB implements IProductB {
        @Override
        public void doB() {
            System.out.println("The ProductB be part of FamilyB");
        }
    }

    /**
     * 抽象工厂接口
     */
    public interface IFactory {
        IProductA makeProductA();

        IProductB makeProductB();
    }

    /**
     * 具体工厂A
     */
    static class ConcreteFactoryA implements IFactory {
        @Override
        public IProductA makeProductA() {
            return new ConcreteProductAWithFamilyA();
        }

        @Override
        public IProductB makeProductB() {
            return new ConcreteProductBWithFamilyA();
        }
    }

    /**
     * 具体工厂B
     */
    static class ConcreteFactoryB implements IFactory {
        @Override
        public IProductA makeProductA() {
            return new ConcreteProductAWithFamilyB();
        }

        @Override
        public IProductB makeProductB() {
            return new ConcreteProductBWithFamilyB();
        }
    }


    public static void main(String[] args) {
        IFactory factory;
        factory = new ConcreteFactoryA();
        factory.makeProductA().doA();
        factory.makeProductB().doB();


        factory = new ConcreteFactoryB();
        factory.makeProductA().doA();
        factory.makeProductB().doB();

    }
}
